﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WF_Business;

public partial class SystemManager_ShowImgEdit : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Bind();
        }
    }

    private void Bind()
    {
        var iid = Request["iid"];
        var strSql = string.Format("select showimg from ut_xwfb where iid='{0}'", iid);
        var imgUrl = SysParams.OAConnection().GetValue(strSql);
        showImg.Src = "../" + imgUrl;
    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (!upfile.HasFile) return;
        try
        {
            var iid = Request["iid"];
            var fileType = Path.GetExtension(upfile.FileName);
            var imgpath = Server.MapPath("../uploadFile/ShowImg/");
            var imgName = Guid.NewGuid().ToString("N") + fileType;
            var imgAllPath = imgpath + imgName;
            if (!Directory.Exists(imgpath))
                Directory.CreateDirectory(imgpath);
            upfile.SaveAs(imgAllPath);
            var _imgpath = "uploadFile/ShowImg/" + imgName;
            showImg.Src = "../" + _imgpath;
            var strSql = string.Format("update ut_xwfb set showimg='{0}' where iid='{1}'", _imgpath, iid);
            SysParams.OAConnection().RunSql(strSql);
            Page.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('保存成功');", true);
        }
        catch (Exception ex)
        {
            Page.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('" + ex.Message + "');", true);
        }
    }
}